<template>
  <div class="app-container-custom">
    <el-row :gutter="10">
      <fold :span="5" :xs="24" :show.sync='sideshow'>
        <el-card shadow="never">
          <repair-project-tree ref="orgTree" @nodeClick="handleNodeClick" @firstNodeClick="handleNodeClick"/>
        </el-card>
      </fold>
      <el-col :span="sideshow ? 19 : 24" :xs="24">
        <el-row :gutter="10" class="mb8">
          <el-col :span="1.5">
            <el-button type="primary" plain size="mini" @click="handleAdd" v-hasPermi="['workorder:repairProject:add']">新增</el-button>
          </el-col>
          <el-col :span="1.5">
            <el-button type="danger" plain size="mini" @click="handleDelete" v-hasPermi="['workorder:repairProject:remove']">删除</el-button>
          </el-col>
        </el-row>
        <el-card shadow="never">
          <repair-project-form  ref="formRef" :currentNode="currentNode"/>
        </el-card>
      </el-col>
    </el-row>
    <repair-project-add-form ref="addFormRef" @ok="$refs.orgTree.refresh()" />
  </div>
</template>

<script>

  import RepairProjectTree from "./repairProjectTree"
  import RepairProjectForm from "./form"
  import RepairProjectAddForm from "./addForm"
  import { delRepairProject } from "@/api/workorder/repairProject";

  export default {
    name: "WorkOrderFit",
    components:{ RepairProjectTree ,RepairProjectForm,RepairProjectAddForm },
    data() {
      return {
        currentNode:{},
        sideshow:true
      }
    },
    methods:{
      handleNodeClick(node){
        this.currentNode = node;
      },
      handleAdd(){
        this.$refs.addFormRef.show({type:'ADD',currentNode:this.currentNode})
      },
      handleDelete(){
        const ids = this.currentNode.id;
        this.$confirm('是否确认报修项目为"' + this.currentNode.label + '"的数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return delRepairProject(ids);
        }).then(() => {
          this.$refs.orgTree.refresh()
          this.msgSuccess("删除报修项目成功");
        }).catch(() => {});
      }
    }
  }
</script>

<style scoped>

</style>
